//
//  ZCEnrollModelContent.m
//
//  Created by   on 16/2/29
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "ZCEnrollModelContent.h"


NSString *const kZCEnrollModelContentId = @"id";
NSString *const kZCEnrollModelContentMid = @"mid";
NSString *const kZCEnrollModelContentName = @"name";
NSString *const kZCEnrollModelContentIsExam = @"is_exam";
NSString *const kZCEnrollModelContentSchool = @"school";
NSString *const kZCEnrollModelContentPrizeLeftCount = @"prize_left_count";
NSString *const kZCEnrollModelContentIsPrize = @"is_prize";
NSString *const kZCEnrollModelContentSchoolid = @"schoolid";
NSString *const kZCEnrollModelContentIsStudy = @"is_study";
NSString *const kZCEnrollModelContentAddress = @"address";
NSString *const kZCEnrollModelContentCtime = @"ctime";
NSString *const kZCEnrollModelContentGrade = @"grade";
NSString *const kZCEnrollModelContentClass = @"mclass";
NSString *const kZCEnrollModelContentScore = @"score";


@interface ZCEnrollModelContent ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ZCEnrollModelContent

@synthesize contentIdentifier = _contentIdentifier;
@synthesize mid = _mid;
@synthesize name = _name;
@synthesize isExam = _isExam;
@synthesize school = _school;
@synthesize prizeLeftCount = _prizeLeftCount;
@synthesize isPrize = _isPrize;
@synthesize schoolid = _schoolid;
@synthesize isStudy = _isStudy;
@synthesize address = _address;
@synthesize ctime = _ctime;
@synthesize grade = _grade;
@synthesize classProperty = _classProperty;
@synthesize score = _score;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.contentIdentifier = [self objectOrNilForKey:kZCEnrollModelContentId fromDictionary:dict];
            self.mid = [self objectOrNilForKey:kZCEnrollModelContentMid fromDictionary:dict];
            self.name = [self objectOrNilForKey:kZCEnrollModelContentName fromDictionary:dict];
            self.isExam = [self objectOrNilForKey:kZCEnrollModelContentIsExam fromDictionary:dict];
            self.school = [self objectOrNilForKey:kZCEnrollModelContentSchool fromDictionary:dict];
            self.prizeLeftCount = [self objectOrNilForKey:kZCEnrollModelContentPrizeLeftCount fromDictionary:dict];
            self.isPrize = [self objectOrNilForKey:kZCEnrollModelContentIsPrize fromDictionary:dict];
            self.schoolid = [self objectOrNilForKey:kZCEnrollModelContentSchoolid fromDictionary:dict];
            self.isStudy = [self objectOrNilForKey:kZCEnrollModelContentIsStudy fromDictionary:dict];
            self.address = [self objectOrNilForKey:kZCEnrollModelContentAddress fromDictionary:dict];
            self.ctime = [self objectOrNilForKey:kZCEnrollModelContentCtime fromDictionary:dict];
            self.grade = [self objectOrNilForKey:kZCEnrollModelContentGrade fromDictionary:dict];
            self.classProperty = [self objectOrNilForKey:kZCEnrollModelContentClass fromDictionary:dict];
            self.score = [self objectOrNilForKey:kZCEnrollModelContentScore fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.contentIdentifier forKey:kZCEnrollModelContentId];
    [mutableDict setValue:self.mid forKey:kZCEnrollModelContentMid];
    [mutableDict setValue:self.name forKey:kZCEnrollModelContentName];
    [mutableDict setValue:self.isExam forKey:kZCEnrollModelContentIsExam];
    [mutableDict setValue:self.school forKey:kZCEnrollModelContentSchool];
    [mutableDict setValue:self.prizeLeftCount forKey:kZCEnrollModelContentPrizeLeftCount];
    [mutableDict setValue:self.isPrize forKey:kZCEnrollModelContentIsPrize];
    [mutableDict setValue:self.schoolid forKey:kZCEnrollModelContentSchoolid];
    [mutableDict setValue:self.isStudy forKey:kZCEnrollModelContentIsStudy];
    [mutableDict setValue:self.address forKey:kZCEnrollModelContentAddress];
    [mutableDict setValue:self.ctime forKey:kZCEnrollModelContentCtime];
    [mutableDict setValue:self.grade forKey:kZCEnrollModelContentGrade];
    [mutableDict setValue:self.classProperty forKey:kZCEnrollModelContentClass];
    [mutableDict setValue:self.score forKey:kZCEnrollModelContentScore];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.contentIdentifier = [aDecoder decodeObjectForKey:kZCEnrollModelContentId];
    self.mid = [aDecoder decodeObjectForKey:kZCEnrollModelContentMid];
    self.name = [aDecoder decodeObjectForKey:kZCEnrollModelContentName];
    self.isExam = [aDecoder decodeObjectForKey:kZCEnrollModelContentIsExam];
    self.school = [aDecoder decodeObjectForKey:kZCEnrollModelContentSchool];
    self.prizeLeftCount = [aDecoder decodeObjectForKey:kZCEnrollModelContentPrizeLeftCount];
    self.isPrize = [aDecoder decodeObjectForKey:kZCEnrollModelContentIsPrize];
    self.schoolid = [aDecoder decodeObjectForKey:kZCEnrollModelContentSchoolid];
    self.isStudy = [aDecoder decodeObjectForKey:kZCEnrollModelContentIsStudy];
    self.address = [aDecoder decodeObjectForKey:kZCEnrollModelContentAddress];
    self.ctime = [aDecoder decodeObjectForKey:kZCEnrollModelContentCtime];
    self.grade = [aDecoder decodeObjectForKey:kZCEnrollModelContentGrade];
    self.classProperty = [aDecoder decodeObjectForKey:kZCEnrollModelContentClass];
    self.score = [aDecoder decodeObjectForKey:kZCEnrollModelContentScore];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_contentIdentifier forKey:kZCEnrollModelContentId];
    [aCoder encodeObject:_mid forKey:kZCEnrollModelContentMid];
    [aCoder encodeObject:_name forKey:kZCEnrollModelContentName];
    [aCoder encodeObject:_isExam forKey:kZCEnrollModelContentIsExam];
    [aCoder encodeObject:_school forKey:kZCEnrollModelContentSchool];
    [aCoder encodeObject:_prizeLeftCount forKey:kZCEnrollModelContentPrizeLeftCount];
    [aCoder encodeObject:_isPrize forKey:kZCEnrollModelContentIsPrize];
    [aCoder encodeObject:_schoolid forKey:kZCEnrollModelContentSchoolid];
    [aCoder encodeObject:_isStudy forKey:kZCEnrollModelContentIsStudy];
    [aCoder encodeObject:_address forKey:kZCEnrollModelContentAddress];
    [aCoder encodeObject:_ctime forKey:kZCEnrollModelContentCtime];
    [aCoder encodeObject:_grade forKey:kZCEnrollModelContentGrade];
    [aCoder encodeObject:_classProperty forKey:kZCEnrollModelContentClass];
    [aCoder encodeObject:_score forKey:kZCEnrollModelContentScore];
}

- (id)copyWithZone:(NSZone *)zone
{
    ZCEnrollModelContent *copy = [[ZCEnrollModelContent alloc] init];
    
    if (copy) {

        copy.contentIdentifier = [self.contentIdentifier copyWithZone:zone];
        copy.mid = [self.mid copyWithZone:zone];
        copy.name = [self.name copyWithZone:zone];
        copy.isExam = [self.isExam copyWithZone:zone];
        copy.school = [self.school copyWithZone:zone];
        copy.prizeLeftCount = [self.prizeLeftCount copyWithZone:zone];
        copy.isPrize = [self.isPrize copyWithZone:zone];
        copy.schoolid = [self.schoolid copyWithZone:zone];
        copy.isStudy = [self.isStudy copyWithZone:zone];
        copy.address = [self.address copyWithZone:zone];
        copy.ctime = [self.ctime copyWithZone:zone];
        copy.grade = [self.grade copyWithZone:zone];
        copy.classProperty = [self.classProperty copyWithZone:zone];
        copy.score = [self.score copyWithZone:zone];
    }
    
    return copy;
}


@end
